/**
* 左边菜单
*/
<template>
  <el-menu default-active="2" :collapse="collapsed" collapse-transition router :default-active="$route.path" unique-opened class="el-menu-vertical-demo" background-color="#334157" text-color="#fff" active-text-color="#ffd04b">
    <div class="logobox">
      <img class="logoimg" src="../assets/img/logo.png" alt="">
    </div>
    <el-submenu v-for="menu in allmenu" :key="menu.menuid" :index="menu.menuname">
      <template slot="title">
        <i class="iconfont" :class="menu.icon"></i>
        <span>{{menu.menuname}}</span>
      </template>
      <el-menu-item-group>
        <template v-for="item in jurisdictionCode">
        <el-menu-item v-for="chmenu in menu.menus" :index="'/'+chmenu.url" :key="chmenu.menuid" v-if="item == chmenu.menuid">
          <i class="iconfont" :class="chmenu.icon"></i>
          <span>{{chmenu.menuname}}</span>
        </el-menu-item>
        </template>
      </el-menu-item-group>
    </el-submenu>
  </el-menu>
</template>
<script>
  import {
    jurisdictionInfo
  } from '../api/adminMG'
  import {
    getStore
  } from '../utils/util'
export default {
  name: 'leftnav',
  data() {
    return {
      collapsed: false,
      allmenu: [],
      jurisdictionCode:[]
    }
  },
  // 创建完毕状态(里面是操作)
  created() {
    // 获取图形验证码
    let res = {
      success: true,
      data: [
        {
          menuid: 150,
          icon: 'li-icon-shujujiankong',
          menuname: '图表',
          hasThird: null,
          url: null,
          menus: [
            {
              menuid: 159,
              icon: 'icon-provider-manage',
              menuname: '数据可视化',
              hasThird: 'N',
              url: 'charts/statistics',
              menus: null
            }
          ]
        },
        {
          menuid: 10,
          icon: 'icon-cat-skuQuery',
          menuname: '菜品管理',
          hasThird: null,
          url: null,
          menus: [
            {
              menuid: 11,
              icon: 'icon-cms-manage',
              menuname: '菜品列表',
              hasThird: 'N',
              url: 'dishes/Dishes',
              menus: null
            },
            {
              menuid: 12,
              icon: 'icon-promotion-manage',
              menuname: '菜品分类',
              hasThird: 'N',
              url: 'dishes/Category',
              menus: null
            }
          ]
        },
        {
          menuid: 20,
          icon: 'li-icon-dingdanguanli',
          menuname: '订单管理',
          hasThird: null,
          url: null,
          menus: [
            {
              menuid: 21,
              icon: 'icon-cms-manage',
              menuname: '订单列表',
              hasThird: 'N',
              url: 'indent/Indents',
              menus: null
            },
            {
              menuid: 22,
              icon: 'icon-promotion-manage',
              menuname: '评论列表',
              hasThird: 'N',
              url: 'indent/Comment',
              menus: null
            },
            {
              menuid: 23,
              icon: 'icon-promotion-manage',
              menuname: '退款管理',
              hasThird: 'N',
              url: 'indent/Chargeback',
              menus: null
            },
            {
              menuid: 24,
              icon: 'icon-order-manage',
              menuname: '订单统计',
              hasThird: 'N',
              url: 'indent/Count',
              menus: null
            }
          ]
        },
        {
          menuid: 30,
          icon: 'li-icon-gongsiguanli',
          menuname: '活动管理',
          hasThird: null,
          url: null,
          menus: [
            {
              menuid: 31,
              icon: 'icon-cat-skuQuery',
              menuname: '满减列表',
              hasThird: 'N',
              url: 'activity/Coupon',
              menus: null
            },
            {
              menuid: 32,
              icon: 'icon-news-manage',
              menuname: '用户满减',
              hasThird: 'N',
              url: 'activity/UserCoupon',
              menus: null
            }
          ]
        },
        {
          menuid: 40,
          icon: 'li-icon-xiangmuguanli',
          menuname: '用户管理',
          hasThird: null,
          url: null,
          menus: [
            {
              menuid: 41,
              icon: 'icon-cus-manage',
              menuname: '用户列表',
              hasThird: 'N',
              url: 'user/User',
              menus: null
            }
          ]
        },
        {
          menuid: 50,
          icon: 'li-icon-xitongguanli',
          menuname: '系统管理',
          hasThird: null,
          url: null,
          menus: [
            {
              menuid: 51,
              icon: 'icon-cs-manage',
              menuname: '店铺管理',
              hasThird: 'N',
              url: 'system/Shop',
              menus: null
            },
            {
              menuid: 52,
              icon: 'icon-cus-manage',
              menuname: '员工管理',
              hasThird: 'N',
              url: 'system/Staff',
              menus: null
            },
            {
              menuid: 53,
              icon: 'icon-news-manage',
              menuname: '角色管理',
              hasThird: 'N',
              url: 'system/StaffRole',
              menus: null
            },
            {
              menuid: 54,
              icon: 'icon-news-manage',
              menuname: '菜单管理',
              hasThird: 'N',
              url: 'system/LeftMenu',
              menus: null
            },
            {
              menuid: 55,
              icon: 'icon-cms-manage',
              menuname: '权限管理',
              hasThird: 'N',
              url: 'system/StaffJurisdictoin',
              menus: null
            }
          ]
        },
        {
          menuid: 60,
          icon: 'li-icon-jichuguanli',
          menuname: '基础管理',
          hasThird: null,
          url: null,
          menus: [
            {
              menuid: 61,
              icon: 'icon-cat-skuQuery',
              menuname: '个人中心',
              hasThird: 'N',
              url: 'basics/SelfCenter',
              menus: null
            }
          ]
        }
      ],
      msg: 'success'
    }
    this.allmenu = res.data

    this.getjurisdictionInfo()

    // menu(localStorage.getItem('logintoken'))
    //   .then(res => {
    //     console.log(JSON.stringify(res))
    //     if (res.success) {
    //       this.allmenu = res.data
    //     } else {
    //       this.$message.error(res.msg)
    //       return false
    //     }
    //   })
    //   .catch(err => {
    //     this.$message.error('菜单加载失败，请稍后再试！')
    //   })
    // 监听
    this.$root.Bus.$on('toggle', value => {
      this.collapsed = !value
    })
  },
  methods:{
    // 获取权限信息
    getjurisdictionInfo(parameter) {
      let _this = this
      this.loading = true
      jurisdictionInfo(getStore('staffInfo').staff_id)
        .then(res => {
          this.loading = false
          if (res.status == 0) {
            this.$message({
              type: 'success',
              message: "获取数据成功"
            })
            console.log("请求权限信息列表——号码", res.data.jurisdictionCode)
            console.log("请求权限信息列表——员工id", res.data.staff_id)
            console.log("请求权限信息列表——角色id", res.data.role_id)
            _this.jurisdictionCode = res.data.jurisdictionCode
            // this.listData = res.data.leftMenuList
            //   // 分页赋值
            //   this.pageparm.currentPage = this.formInline.page
            //   this.pageparm.pageSize = this.formInline.limit
            //   this.pageparm.total = res.count
          } else {
            this.$message({
              type: 'warning',
              message: "获取权限信息列表失败"
            })
          }
        })
        .catch(err => {
          this.loading = false
          this.$message.error('权限信息加载失败，请稍后再试！')
        })
    },
  }
}
</script>
<style>
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 240px;
  min-height: 400px;
}
.el-menu-vertical-demo:not(.el-menu--collapse) {
  border: none;
  text-align: left;
}
.el-menu-item-group__title {
  padding: 0px;
}
.el-menu-bg {
  background-color: #1f2d3d !important;
}
.el-menu {
  border: none;
}
.logobox {
  height: 40px;
  line-height: 40px;
  color: #9d9d9d;
  font-size: 20px;
  text-align: center;
  padding: 20px 0px;
}
.logoimg {
  height: 40px;
}
</style>
